<?php
class AutocompleteModel{
	public static function getUsers($term){
		$db = Zend_Registry::get('connectDB');
		$select = $db->select()
					->distinct()
					->from(array('u' => 'user'), array('id'=>'u.id', 'name'=>'u.name', 'username'=>'u.username', 'phone'=>'u.phone'))
					->where("u.username like '%$term%' or u.name like '%$term%'")
					->where("status = 1 and type = 1")
					->limit(10);
		$list = $db->fetchAll($select);
		
        foreach ($list as $row){
            $temp["id"] = $row['id'];
            $temp["data"] = $row['id'].",".$row['username'].",".$row['name'].",".$row['phone'];
            $temp["label"] = '<span>'.$row['name'].'<span>';
            $temp["value"] = $row['username'];
            $arr[] = $temp;
        }
        
        return $arr;
	}
}